package thread;

//使用interrupt()提前唤醒线程
public class Thread_interrupt_wakeup {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "线程开始");
            try {
                Thread.sleep(1000 * 60 * 60);//使线程休眠24小时
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "线程结束");
        });
        thread.start();
        //将长时间睡眠的线程,3秒后唤醒
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //尝试提前唤醒线程
        thread.interrupt();
    }
}